<?php
/*
 * Created on 2011-2-18
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
//$siteRoot=trim($_SERVER['SCRIPT_FILENAME'],strstr($_SERVER['SCRIPT_FILENAME'],'/web'));
$siteRoot = dirname(__FILE__);
 define( "SITE_ROOT",$siteRoot);
 define ("FILES_ROOT",SITE_ROOT . '/files');
 require_once(SITE_ROOT."/function/YiLook.php");
 require_once(SITE_ROOT."/function/Generator.php");
 require_once(SITE_ROOT."/function/FileAction.php");
 

	
	if(!isset($_POST['chapter_url'])){
		
		include("index2.php");
		//exit();
	}else {
		
	$chapterUrl=trim($_POST['chapter_url']);
	//简单错误处理
	if(empty($chapterUrl)) $errorMessage="地址不能为空";	
	elseif(false === strpos($chapterUrl,'art_')) $errorMessage="地址不正确";
	
	if (isset($errorMessage)){
		include("error.php");
		die();
	}
	
	
	$type=isset($_POST['type'])?trim($_POST['type']):'txt';
	
	
	set_time_limit(0);
	$g=new Generator($chapterUrl);
	$file=$g->write(FILES_ROOT);
	if ($file!==false)
	$downFile=new FileAction();
	$fileInfo=pathinfo($file);
	
	
	if ($type=='zip'){
		//生成zip文件 下载
		$displayName=$fileInfo['filename'].'.zip';
		$downFile->download_zip($file,$displayName);
	}else{
		//生成txt文件下载
		$displayName=$fileInfo['filename'].'.txt';
		$downFile->download_txt($file);
	}
	}
	
	

 
?>
